package com.hsck.order.kds.main.dialog

import android.app.Activity
import android.app.Dialog
import android.view.LayoutInflater
import android.view.WindowManager
import androidx.databinding.DataBindingUtil
import androidx.recyclerview.widget.LinearLayoutManager
import com.hsck.order.kds.R
import com.hsck.order.kds.base.utils.setOnSingleClickListener
import com.hsck.order.kds.databinding.ComboDialogLayoutBinding
import com.hsck.order.kds.main.fragment.standard.bean.TestListBean
import com.hsck.order.kds.main.fragment.standard.adapter.ComboItemAdapter

/**
 * 套餐弹窗
 */
class ComboDialog(val context: Activity) : Dialog(context, R.style.Dialog_FullScreen) {

    private val activity: Activity = context
    private val comboItemAdapter = ComboItemAdapter()

    private var binding: ComboDialogLayoutBinding = DataBindingUtil.inflate(
        LayoutInflater.from(context),
        R.layout.combo_dialog_layout,
        null,
        false
    )

    init {
        createDialog()
    }

    private fun createDialog() {
        setContentView(binding.root)
        setCanceledOnTouchOutside(false)
        setCancelable(false)
        val lp = window?.attributes
        lp?.width = WindowManager.LayoutParams.MATCH_PARENT
        lp?.height = WindowManager.LayoutParams.WRAP_CONTENT

        lp?.alpha = 1f
        window?.attributes = lp
        if (activity.isFinishing) {
            return
        }
        binding.viewClose.setOnSingleClickListener { dismiss() }
        initRecyclerView()
    }

    private fun initRecyclerView() {
        val layoutManager = LinearLayoutManager(context)
        layoutManager.orientation = LinearLayoutManager.VERTICAL
        binding.recyclerView.layoutManager = layoutManager
        binding.recyclerView.adapter = comboItemAdapter
    }

    fun show(dishName: String, list: MutableList<TestListBean>) {
        binding.tvComboTitle.text = dishName
        comboItemAdapter.submitList(list)
        show()
    }
}
